/* configuration file */
var my = {
"width":{
	"base"  : 32, // [bit] 2^n
	"fetch" : 32, // [bit] 2^n
	"ir"    : 8   // [fetch words] 2^n
},
"isa":{ // instruction format tree
	"0": [
		"Postcard",
		{"1": [
			{"2":["Letter","Local"]},
			{"2": [
				{"3": ["p12", "p16"]},
				{"3": ["Literal", "Branch"]}
			]}
		]}
	]
},
"parcels":{ // all instuction formats
	"Postcard" : [4,  {"op" : [3,1]}, "Most common 0-operand words."],
	"Letter"   : [8,  {"op" : [7,3]}, "Bigger set of common words."],
	"Local"    : [8,  {"op" : [7,3]}, "Operations with locals on both stacks."],
	"p12"      : [12, {"op" : [6,4],  "literal" : [11,7]}, "common sequences with literal"],
	"p16"      : [16, {
		"rs&#xB1;"   : [15, 14, "0", "+1", "-2", "-1"],
		"ds&#xB1;"   : [13, 12, "0", "+1", "-2", "-1"],
		"alu"        : [11, 8, "t", "n", "t+n", "t&n", "t|n", "t^n", "~t", "n==t", "n<t", "n>>t", "t-1", "r", "[t]", "n<<t", "depth", "nu<t"],
		"pc"  : 7,
		"n"   : 6,
		"r"   : 5,
		"[t]" : 4
	}, "Novix-style instruction. (Fix me!)"],
	"Branch"  : [28, {"addr":[27,7], "op":[6, 4]}, "Branch instructions. Nibble address."],
	"Literal" : [36, {"literal":[35,4]}, "Long literal"]
},
"liw":[
	{"a"    : 8},
	{"b"    : 8},
	{"d"    : 8},
	{"(d)"  : 8},
	{"c"    : 8},
	{"(c)"  : 8},
	{"ls"   : 8},
	{"ds"   : 2},
	{"rs"   : 2},
	{"lit"  : 32},
	{"goto" : 32}
],
"Postcard":{
        "EXIT"      : [{"op":0 }, {         "rs":-1,                                                                "goto":"r0"}],
        "DROP"      : [{"op":1 }, {"ds":-1 }],
        "+"         : [{"op":2 }, {"ds":-1, "a":"s1", "b":"s0",            "(d)":"a+b",                          "d":"s0"}],
        "DUP"       : [{"op":3 }, {"ds": 1,           "b":"s0",            "(d)":"b",                            "d":"s0"}],
        "OVER"      : [{"op":4 }, {"ds": 1, "a":"s1",                      "(d)":"a",                            "d":"s0"}],
        "SWAP"      : [{"op":5 }, {         "a":"s1", "b":"s0", "(c)":"b", "(d)":"a", "c":"s1",                  "d":"s0"}],
        "i32@"      : [{"op":6 }, {         "a":"s0",                      "(d)":"ls",          "ls":"i32[a]",   "d":"s0"}],
        "i32!"      : [{"op":7 }, {"ds":-2, "a":"s1", "b":"s0",                                 "ls":"i32[a]=b", "d":"s0"}]
},
"Local":{
	"R@"        : [{"op":0 }, {"ds": 1, "d":"s0", "a":"r0", "(d)":"a"}],
	"R1@"       : [{"op":1 }, {"ds": 1, "d":"s0", "a":"r1", "(d)":"a"}],
	"R2@"       : [{"op":2 }, {"ds": 1, "d":"s0", "a":"r2", "(d)":"a"}],
	"R3@"       : [{"op":3 }, {"ds": 1, "d":"s0", "a":"r3", "(d)":"a"}],
	"R4@"       : [{"op":4 }, {"ds": 1, "d":"s0", "a":"r4", "(d)":"a"}],
	"R5@"       : [{"op":5 }, {"ds": 1, "d":"s0", "a":"r5", "(d)":"a"}],
	"R6@"       : [{"op":6 }, {"ds": 1, "d":"s0", "a":"r6", "(d)":"a"}],
	"R7@"       : [{"op":7 }, {"ds": 1, "d":"s0", "a":"r7", "(d)":"a"}],

	"DUP"       : [{"op":8 }, {"ds": 1, "d":"s0", "a":"s0", "(d)":"a"}],
	"OVER"      : [{"op":9 }, {"ds": 1, "d":"s0", "a":"s1", "(d)":"a"}],
	"2 PICK"    : [{"op":10}, {"ds": 1, "d":"s0", "a":"s2", "(d)":"a"}],
	"3 PICK"    : [{"op":11}, {"ds": 1, "d":"s0", "a":"s3", "(d)":"a"}],
	"4 PICK"    : [{"op":12}, {"ds": 1, "d":"s0", "a":"s4", "(d)":"a"}],
	"5 PICK"    : [{"op":13}, {"ds": 1, "d":"s0", "a":"s5", "(d)":"a"}],
	"6 PICK"    : [{"op":14}, {"ds": 1, "d":"s0", "a":"s6", "(d)":"a"}],
	"7 PICK"    : [{"op":15}, {"ds": 1, "d":"s0", "a":"s7", "(d)":"a"}],

	"R!"        : [{"op":16}, {"ds":-1, "d":"r0", "b":"s0", "(d)":"b"}],
	"R1!"       : [{"op":17}, {"ds":-1, "d":"r1", "b":"s0", "(d)":"b"}],
	"R2!"       : [{"op":18}, {"ds":-1, "d":"r2", "b":"s0", "(d)":"b"}],
	"R3!"       : [{"op":19}, {"ds":-1, "d":"r3", "b":"s0", "(d)":"b"}],
	"R4!"       : [{"op":20}, {"ds":-1, "d":"r4", "b":"s0", "(d)":"b"}],
	"R5!"       : [{"op":21}, {"ds":-1, "d":"r5", "b":"s0", "(d)":"b"}],
	"R6!"       : [{"op":22}, {"ds":-1, "d":"r6", "b":"s0", "(d)":"b"}],
	"R7!"       : [{"op":23}, {"ds":-1, "d":"r7", "b":"s0", "(d)":"b"}],

	"DSP@"      : [{"op":24}, {"ds": 1, "d":"s0", "a":"dsp", "(d)":"a"}],
	"RSP@"      : [{"op":25}, {"ds": 1, "d":"s1", "a":"rsp", "(d)":"a"}],
	"PC@"       : [{"op":26}, {"ds": 1, "d":"s2", "a":"pc", "(d)":"a"}],
	"PID@"      : [{"op":27}, {"ds": 1, "d":"s3", "a":"pid", "(d)":"a"}],
	"DSP!"      : [{"op":28}, {"ds":-1, "d":"dsp","b":"s0", "(d)":"b"}],
	"RSP!"      : [{"op":29}, {"ds":-1, "d":"rsp","b":"s0", "(d)":"b"}],
	"PC!"       : [{"op":30}, {"ds":-1, "d":"pc", "b":"s0", "(d)":"b"}],
	"PID!"      : [{"op":31}, {"ds":-1, "d":"pid","b":"s0", "(d)":"b"}]
},
"Letter":{

	"R>"        : [{"op":8 }, {"ds": 1, "a":"r0",                      "(d)":"a",      "d":"s0", "rs":-1}],

	">R"        : [{"op":9 }, {"ds":-1,   "b":"s0",            "(d)":"a",      "d":"r0", "rs": 1}],
	"i8@"       : [{"op":16}, {           "b":"s0",            "(d)":"i8[a]",  "d":"s0"}],
	"i16@"      : [{"op":17}, {           "b":"s0",            "(d)":"i16[a]", "d":"s0"}],
	"1 +"       : [{"op":18}, {"a":"lit", "b":"s0", "d":"s0",  "(d)":"a+b",    "lit" : 1}],
	"4 +"       : [{"op":19}, {"a":"lit", "b":"s0", "d":"s0",  "(d)":"a+b",    "lit" : 4}],
	"1 -"       : [{"op":20}, {"a":"lit", "b":"s0", "d":"s0",  "(d)":"a+b",    "lit" :-1}],

	"NEGATE"    : [{"op":21}, {"b":"s0", "(d)":"-b",    "d":"s0"}],
	"INVERT"    : [{"op":22}, {"b":"s0", "(d)":"~b",    "d":"s0"}],
	"2*"        : [{"op":23}, {"b":"s0", "(d)":"b<<1",  "d":"s0"}],
	"2/"        : [{"op":24}, {"b":"s0", "(d)":"b>>1",  "d":"s0"}],
	"U2/"       : [{"op":24}, {"b":"s0", "(d)":"b>>1",  "d":"s0"}],
	"0="        : [{"op":25}, {"b":"s0", "(d)":"b=0",   "d":"s0"}],
	"0<"        : [{"op":26}, {"b":"s0", "(d)":"b>>32", "d":"s0"}],
	"ABS"       : [{"op":27}, {"b":"s0", "(d)":"|b|",   "d":"s0"}],
	"NEGATE"    : [{"op":21}, {"b":"s0", "(d)":"-b",    "d":"s0"}],

	
	"SWAP DROP" : [{"op":28}, {"ds":-1,          "b":"s0",             "(d)":"b",             "d":"s0"}], // nip

	"i8!"       : [{"op":29}, {"ds":-2, "a":"s1", "b":"s0",            "(d)":"i8[a]=b",       "d":"s0"}],
	"i16!"      : [{"op":30}, {"ds":-2, "a":"s1", "b":"s0",            "(d)":"i16[a]=b",      "d":"s0"}],

	"OR"        : [{"op":31}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a|b"}],
	"XOR"       : [{"op":32}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a^b"}],
	"AND"       : [{"op":33}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a&b"}],
	"OR NOT"    : [{"op":34}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a&b"}],
	"AND NOT"   : [{"op":35}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a&b"}],
	"*"         : [{"op":36}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a*b"}],
	"-"         : [{"op":37}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a-b"}],
	"M*"        : [{"op":38}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a*b"}],
	"UM*"       : [{"op":39}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a*b"}],
	"/"         : [{"op":40}, {"ds":-1, "a":"s1", "b":"s0", "d":"s0",  "(d)":"a/b"}],

	"        IF EXIT THEN" : [{"op":60}, {"ds":-1, "rs":"s0 ? -1 : 0", "goto":"|s0 ? r0 : pc_nxt"}],
	"    DUP IF EXIT THEN" : [{"op":61}, {         "rs":"s0 ? -1 : 0", "goto":"|s0 ? r0 : pc_nxt"}],
	"    0 = IF EXIT THEN" : [{"op":62}, {"ds":-1, "rs":"s0 ? 0 : -1", "goto":"|s0 ? pc_nxt : r0"}],
	"DUP 0 = IF EXIT THEN" : [{"op":63}, {         "rs":"s0 ? 0 : -1", "goto":"|s0 ? pc_nxt : r0"}]
},
"p12":{
	"[0:1:31] + i32@" : [{"op" : 0, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds": 1, "ls":"i32[b]"}],
	"[0:1:31] + i32!" : [{"op" : 1, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds":-1, "ls":"i32[b]=a"}],
	"[0:1:31] + i16@" : [{"op" : 2, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds": 1, "ls":"i16[b]"}],
	"[0:1:31] + i16!" : [{"op" : 3, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds":-1, "ls":"i16[b]=a"}],
	"[0:1:31] +  i8@" : [{"op" : 4, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds": 1, "ls":"i8[b]"}],
	"[0:1:31] +  i8!" : [{"op" : 5, "literal" : "$1"}, {"lit" : "literal", "a":"lit", "ds":-1, "ls":"i8[b]=a"}],
	"[-16:1:15]    +" : [{"op" : 6, "literal" : "$1"}, {"lit" : "literal", "a":"lit"}],
	"[-16:1:15]     " : [{"op" : 7, "literal" : "$1"}, {"lit" : "literal", "a":"lit"}]
},
"Branch":{
	"[0:1:2097151]       ELSE" : [{"op":0, "addr":"$1", "pg":0}, {         "goto":"addr"}],
	"[0:1:2097151]         IF" : [{"op":1, "addr":"$1", "pg":0}, {"ds":-1, "goto":"|s0 ? pc_nxt : addr"}],
	"[0:1:2097151]     DUP IF" : [{"op":2, "addr":"$1", "pg":0}, {         "goto":"|s0 ? pc_nxt : addr"}],
	"[0:1:2097151]     0 = IF" : [{"op":3, "addr":"$1", "pg":0}, {"ds":-1, "goto":"|s0 ? addr   : pc_nxt "}],
	"[0:1:2097151] DUP 0 = IF" : [{"op":4, "addr":"$1", "pg":0}, {         "goto":"|s0 ? addr   : pc_nxt "}],
	"[0:1:2097151]       NEXT" : [{"op":5, "addr":"$1", "pg":0}, {"a":"r0", "(d)":"a-1", "d":"r0", "rs":"r0 ? -1 : 0", "goto":"|r0 ? addr : pc_nxt"}],
	"[0:1:2097151]       CALL" : [{"op":6, "addr" : "$1"}, {"goto":"addr", "a":"pc_nxt", "(d)":"a", "d":"r0", "rs":1}]
},
"Literal":{
	"[-2147483648:1:2147483647]" : [{"literal" : "$1"}, {"ds":1, "a":"literal", "(d)":"a", "d":"s0"}]
}
}

/*
ToDo
+-
with carry
i16 i16 +-
i8 i8 i8 i8 +-



*/